import json
import copy

def save_recipes_pretty(recipes, filename):
    """
    以美化格式保存配方数据到 JSON 文件
    """
    try:
        with open(filename, 'w', encoding='utf-8') as file:
            json.dump(recipes, file,
                      ensure_ascii=False,
                      indent=2,  # 2个空格缩进
                      sort_keys=False)  # 保持原始键顺序

        print(f"配方数据已美化保存到: {filename}")
        return True

    except Exception as e:
        print(f"保存文件时出错: {e}")
        return False


def partial_deepcopy(src: dict, keys):
    return {k: copy.deepcopy(src[k]) for k in keys if k in src}

def partial_deepcopy(src: dict, keys, res):
    for k in keys:
        if k in src:
            res[k] = copy.deepcopy(src[k])
